package com.jsjosem.aftersales.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.jsjosem.aftersales.R;
import com.jsjosem.aftersales.data.model.HomeRank;
import com.jsjosem.aftersales.data.response.WorkRankingsResponse;

import java.util.List;

public class HomeRankListAdapter extends ArrayAdapter<WorkRankingsResponse> {
    public HomeRankListAdapter(@NonNull Context context, int resource, @NonNull List<WorkRankingsResponse> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        WorkRankingsResponse item = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.home_rank_item_list, parent, false);
        ImageView rankIv = view.findViewById(R.id.homepages_first);
        TextView rankTv = view.findViewById(R.id.home_rank_tv);
        TextView name = view.findViewById(R.id.first_name);
        TextView count = view.findViewById(R.id.first_count);
        switch (item.getRank()) {
            case 1:
                rankIv.setImageResource(R.drawable.icon_homepages_first);
                break;
            case 2:
                rankIv.setImageResource(R.drawable.icon_homepages_second_24dp);
                break;
            case 3:
                rankIv.setImageResource(R.drawable.icom_homepages_third_24dp);
                break;
            default:
                rankTv.setVisibility(View.VISIBLE);
                rankIv.setVisibility(View.GONE);
                break;
        }
        name.setText(item.getRealname());
        count.setText("完成 " + item.getCount());
        rankTv.setText(String.valueOf(item.getRank()));
        return view;
    }
}
